#include <iostream>

using namespace std;
const int N = 2010, mod = 1e9 + 7;
int c[N][N];

void inti()
{
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j <= i; ++j)
        {
            if (!j)
            {
                c[i][j] = 1;
            }
            else
            {
                c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
            }
        }
    }
}
int main()
{
    int n;
    cin >> n;
    inti();
    int a, b;
    while(n--)
    {
        scanf("%d %d", &a, &b);
        printf("%d\n", c[a][b]);
    }
    return 0;
}